package com.github.natholdallas.controller.admin

import com.github.natholdallas.common.*
import com.github.natholdallas.database.OrderTable
import com.github.natholdallas.database.TopupTable
import com.github.natholdallas.database.User
import com.github.natholdallas.database.Users
import com.github.natholdallas.declaration.ModelSerializer
import java.math.BigDecimal


data class AdminIn(
    val username: String,
    val password: String,
    val role: Role,
    val name: String?,
    val avatar: String?
) : ModelSerializer<User> {
    override fun get() = User(
        username = username,
        password = password,
        role = role,
        name = name,
        avatar = avatar
    )

    override fun set(v: User) {
        v.username = username
        v.password = password
        v.role = role
        v.name = name
        v.avatar = avatar
    }
}

data class UserIn(
    val username: String,
    val password: String,
    val name: String?,
    var avatar: String?,
    val amount: BigDecimal,
    val balance: BigDecimal
) : ModelSerializer<User> {
    override fun get() = User(
        role = Role.USER,
        username = username,
        password = password,
        name = name,
        avatar = avatar,
        amount = amount,
        balance = balance
    )

    override fun set(v: User) {
        v.role = Role.USER
        v.username = username
        v.password = password
        v.name = name
        v.avatar = avatar
        v.amount = amount
        v.balance = balance
    }
}


data class CopilotIn(
    val username: String,
    val password: String,
    val name: String?,
    val avatar: String?,
    val description: String?,
    val gender: Gender,
    val phone: String?,
    val qrcode: String?,
) : ModelSerializer<User> {
    override fun get() = User(
        role = Role.COPILOT,
        username = username,
        password = password,
        name = name,
        avatar = avatar,
        description = description,
        gender = gender,
        phone = phone,
        qrcode = qrcode
    )

    override fun set(v: User) {
        v.role = Role.COPILOT
        v.username = username
        v.password = password
        v.name = name
        v.avatar = avatar
        v.description = description
        v.gender = gender
        v.phone = phone
        v.qrcode = qrcode
    }
}


data class TopupIn(
    val user: Long,
    val description: String?,
    val amount: BigDecimal,
    val gift: BigDecimal
) : ModelSerializer<TopupTable> {
    override fun get() = TopupTable(
        user = getBean(Users::class).byId(user),
        description = description,
        amount = amount,
        gift = gift
    )

    override fun set(v: TopupTable) {
        v.user = getBean(Users::class).byId(user)
        v.description = description
        v.amount = amount
        v.gift = gift
    }
}


data class OrderIn(
    val user: Long,
    val copilot: Long,
    val description: String?,
    val type: OrderType,
    val price: Int,
    val duration: Int,
) : ModelSerializer<OrderTable> {
    override fun get() = OrderTable(
        user = getBean(Users::class).byId(user),
        copilot = getBean(Users::class).byId(copilot),
        description = description,
        type = type,
        price = price,
        duration = duration
    )

    override fun set(v: OrderTable) {
        v.user = getBean(Users::class).byId(user)
        v.copilot = getBean(Users::class).byId(copilot)
        v.description = description
        v.type = type
        v.price = price
        v.duration = duration
    }
}
